package student.object.thread.wait;

public class WaitService implements student.object.thread.Service {

    public void mSleep() {
        synchronized (this) {
            try {
                System.out.println(Thread.currentThread().getName() + " 开始睡眠3秒");
                Thread.sleep(3 * 1000);
                System.out.println(Thread.currentThread().getName() + " 睡眠3秒结束");
                this.notifyAll();
                System.out.println(Thread.currentThread().getName() + " 开始唤醒等待");
            } catch (Exception e) {
                System.out.println(e);
            }
        }
    }

    public void mWait() {
        synchronized (this) {
            try {
                System.out.println(Thread.currentThread().getName() + " 等待开始");
                this.wait(); // 该方法 一直等待，没有超时时间这个概念。可以设置时间。
                System.out.println(Thread.currentThread().getName() + " 等待结束");
            } catch (Exception e) {
                System.out.println(e);
            }
        }
    }
}